package com.btex.app.treaty.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.btex.app.MyApplication;
import com.btex.app.R;
import com.btex.app.entity.ChengJiaoInfo;
import com.btex.app.tools.Tools;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/11/1
 * @time 上午11:48
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class ChengJiaoAdapter extends BaseQuickAdapter<ChengJiaoInfo.DataBean, BaseViewHolder> {


    private String mNumbers = "8";
    private String mPriceNumber = "2";
    private String mContract_value = "1";
    private String mIszheng;
    private String mMSettle_anchor;

    public ChengJiaoAdapter() {
        super(R.layout.item_cheng_jiao);
    }

    @Override
    protected void convert(BaseViewHolder helper, ChengJiaoInfo.DataBean item) {

//        合约
        TextView item_treaty_history_tv_entrust_name = (TextView) helper.getView(R.id.item_treaty_history_tv_entrust_name);
//        时间
        TextView item_treaty_tv_entrust_history_time = (TextView) helper.getView(R.id.item_treaty_tv_time);
//        委托类型
        TextView item_treaty_tv_entrust_history_type = (TextView) helper.getView(R.id.item_treaty_tv_entrust_history_type);
//        成交数量
        TextView item_treaty_tv_entrust_history_number = (TextView) helper.getView(R.id.item_treaty_tv_entrust_history_number);
//        委托价格
        TextView item_treaty_tv_entrust_history_price = (TextView) helper.getView(R.id.item_treaty_tv_entrust_history_price);
//        成交价格
        TextView item_treaty_tv_entrust_chengjiao_history_jiage = (TextView) helper.getView(R.id.item_treaty_tv_entrust_chengjiao_history_jiage);
//        成交价值
        TextView item_treaty_tv_entrust_chengjiao_history_price = (TextView) helper.getView(R.id.item_treaty_tv_entrust_chengjiao_history_price);
//        手续费
        TextView item_treaty_tv_entrust_chengjiao_shouxufei = (TextView) helper.getView(R.id.item_treaty_tv_entrust_chengjiao_shouxufei);
//        多空
        TextView item_treaty_tv_entrust_history_duokong = (TextView) helper.getView(R.id.item_treaty_tv_entrust_history_duokong);
//        杠杆
        TextView item_treaty_tv_entrust_history_ganggan = (TextView) helper.getView(R.id.item_treaty_tv_entrust_history_ganggan);
        View item_entrust_history_view_type = helper.getView(R.id.item_entrust_history_view_type);

        String order_price = item.getOrder_price();
        String leverage = item.getLeverage();
        String price = item.getPrice();
        String trade_num = item.getTrade_num();
        String order_type = item.getOrder_type();

        String type = item.getType();
        int time = item.getTime();


        String timedate = Tools.timedate(String.valueOf(time));
        item_treaty_tv_entrust_history_number.setText(trade_num);
        item_treaty_history_tv_entrust_name.setText(item.getSymbol());
        item_treaty_tv_entrust_history_time.setText(timedate);

        String shouxufei = Tools.round(Double.valueOf(item.getTrade_fee()), Integer.valueOf(mNumbers)).toString().trim();
        item_treaty_tv_entrust_chengjiao_shouxufei.setText(shouxufei + "\t" + "\t" + mMSettle_anchor);


        String is_cross = item.getIs_cross();
        if ("1".equals(is_cross)) {
//            全仓
            item_treaty_tv_entrust_history_ganggan.setText("(" + "全仓" + leverage + "X" + ")");

        } else {
            item_treaty_tv_entrust_history_ganggan.setText("(" + "逐仓" + leverage + "X" + ")");
        }


        if ("limit".equals(order_type)) {
            item_treaty_tv_entrust_history_type.setText("限价");
            String chengjiao_price = Tools.round(Double.valueOf(price), Integer.valueOf(mPriceNumber)).toString().trim();
            item_treaty_tv_entrust_chengjiao_history_jiage.setText(chengjiao_price);
            String trim = Tools.round(Double.valueOf(order_price), Integer.valueOf(mPriceNumber)).toString().trim();
            item_treaty_tv_entrust_history_price.setText(trim);


        } else {
            String chengjiao_price = Tools.round(Double.valueOf(price), Integer.valueOf(mPriceNumber)).toString().trim();
            item_treaty_tv_entrust_chengjiao_history_jiage.setText(chengjiao_price);
            item_treaty_tv_entrust_history_type.setText("市价");
            item_treaty_tv_entrust_history_price.setText("市价");

        }


        if ("1".equals(mIszheng)) {


//            反向
            Double cPrice = Double.valueOf(price);
            Double cTradeNum = Double.valueOf(trade_num);
            double v = cTradeNum / cPrice * Double.valueOf(mContract_value);
            String trim1 = Tools.round(v, Integer.valueOf(mNumbers)).toString().trim();
            if (!TextUtils.isEmpty(mMSettle_anchor)) {

                item_treaty_tv_entrust_chengjiao_history_price.setText(trim1 + "\t" + "\t" + mMSettle_anchor);
            }


        } else {

            Double cPrice = Double.valueOf(price);
            Double cTradeNum = Double.valueOf(trade_num);
            double v = cTradeNum * cPrice * Double.valueOf(mContract_value);
            String trim1 = Tools.round(v, Integer.valueOf(mNumbers)).toString().trim();
            if (!TextUtils.isEmpty(mMSettle_anchor)) {

                item_treaty_tv_entrust_chengjiao_history_price.setText(trim1 + "\t" + "\t" + mMSettle_anchor);
            }


        }


        if ("sell".equals(type)) {
            item_entrust_history_view_type.setBackgroundColor(MyApplication.getContextObject().getColor(R.color.red));
//            item_treaty_tv_entrust_history_duokong.setTextColor(MyApplication.getContextObject().getColor(R.color.red));
            item_treaty_tv_entrust_history_duokong.setText("空");

        } else {
            item_entrust_history_view_type.setBackgroundColor(MyApplication.getContextObject().getColor(R.color.bg_green));
            item_treaty_tv_entrust_history_duokong.setText("多");
//            item_treaty_tv_entrust_history_duokong.setTextColor(MyApplication.getContextObject().getColor(R.color.bg_green));
        }


    }

    public void setNumber(String numbers) {


        mNumbers = numbers;
    }

    public void setPriceNumber(String PriceNumber) {

        mPriceNumber = PriceNumber;
    }

    public void setmContract_value(String Contract_value) {

        mContract_value = Contract_value;
    }

    public void setIszheng(String iszheng) {

        mIszheng = iszheng;
    }

    public void setmSettleanchor(String mSettle_anchor) {

        mMSettle_anchor = mSettle_anchor;
    }

}
